/*
 * define.h
 *
 *  Created on: 2018��3��1��
 *      Author: anve
 */

#ifndef DEFINE_H_
#define DEFINE_H_

#include <stdint.h>
#include "stm32h7xx_hal.h"

typedef uint8_t BYTE;
typedef uint16_t WORD;
typedef uint8_t u8;
typedef uint32_t u32;
typedef uint16_t u16;
typedef uint64_t u64;

#define U16 u16
#define U8 u8
#define U32 u32
#define U64 u64

typedef unsigned char	UCHAR;

#define U8_MAX     ((u8)255)
#define S8_MAX     ((s8)127)
#define S8_MIN     ((s8)-128)
#define U16_MAX    ((u16)65535u)
#define S16_MAX    ((s16)32767)
#define S16_MIN    ((s16)-32768)
#define U32_MAX    ((u32)4294967295uL)
#define S32_MAX    ((s32)2147483647)
#define S32_MIN    ((s32)-2147483648)



typedef volatile uint32_t vu32;

#define ABS(x) ((x)<0?-(x):(x))


#define BIT0 (0x01)
#define BIT1 (0x02)
#define BIT2 (0x04)
#define BIT3 (0x08)
#define BIT4 (0x10)
#define BIT5 (0x20)
#define BIT6 (0x40)
#define BIT7 (0x80)



typedef enum{
	FALSE = 0,
	TRUE   = 1,
}  bool;

typedef enum{
	Bit_RESET,
	Bit_SET,

}BitAction;

typedef BitAction bit;


#define GPIO_SetBits(port, pin) HAL_GPIO_WritePin(port, pin, GPIO_PIN_SET)
#define GPIO_ResetBits(port, pin) HAL_GPIO_WritePin(port, pin, GPIO_PIN_RESET)
#define GPIO_Init HAL_GPIO_Init
#define GPIO_ReadInputDataBit HAL_GPIO_ReadPin


#define BITBAND(addr, bitnum) ((addr & 0xF0000000)+0x2000000+((addr &0xFFFFF)<<5)+(bitnum<<2))

#define MEM_ADDR(addr)  *((volatile unsigned long  *)(addr))

#define BIT_ADDR(addr, bitnum)   MEM_ADDR(BITBAND(addr, bitnum))

//����������STM32F207, ��������STM32F103
//IO�ڵ�ַӳ��

#define GPIOA_ODR_Addr    (GPIOA_BASE+0x14) //0x4001080C
#define GPIOB_ODR_Addr    (GPIOB_BASE+0x14) //0x40010C0C
#define GPIOC_ODR_Addr    (GPIOC_BASE+0x14) //0x4001100C
#define GPIOD_ODR_Addr    (GPIOD_BASE+0x14) //0x4001140C
#define GPIOE_ODR_Addr    (GPIOE_BASE+0x14) //0x4001180C
#define GPIOF_ODR_Addr    (GPIOF_BASE+0x14) //0x40011A0C
#define GPIOG_ODR_Addr    (GPIOG_BASE+0x14) //0x40011E0C

// added by anve 2018.1.28
#define GPIOH_ODR_Addr    (GPIOH_BASE+0x14)
#define GPIOI_ODR_Addr    (GPIOI_BASE+0x14)
#define GPIOJ_ODR_Addr    (GPIOJ_BASE+0x14)
#define GPIOK_ODR_Addr    (GPIOK_BASE+0x14)
// end by anve




#define GPIOA_IDR_Addr    (GPIOA_BASE+0x10) //0x40010808
#define GPIOB_IDR_Addr    (GPIOB_BASE+0x10) //0x40010C08
#define GPIOC_IDR_Addr    (GPIOC_BASE+0x10) //0x40011008
#define GPIOD_IDR_Addr    (GPIOD_BASE+0x10) //0x40011408
#define GPIOE_IDR_Addr    (GPIOE_BASE+0x10) //0x40011808
#define GPIOF_IDR_Addr    (GPIOF_BASE+0x10) //0x40011A08
#define GPIOG_IDR_Addr    (GPIOG_BASE+0x10) //0x40011E08

// added by anve 2018.1.28
#define GPIOH_IDR_Addr    (GPIOH_BASE+0x10)
#define GPIOI_IDR_Addr    (GPIOI_BASE+0x10)
#define GPIOJ_IDR_Addr    (GPIOJ_BASE+0x10)
#define GPIOK_IDR_Addr    (GPIOK_BASE+0x10)
// end by anve




//IO�ڲ���,ֻ�Ե�һ��IO��!
//ȷ��n��ֵС��16!
#define PAout(n)   BIT_ADDR(GPIOA_ODR_Addr,n)  //���
#define PAin(n)    BIT_ADDR(GPIOA_IDR_Addr,n)  //����

#define PBout(n)   BIT_ADDR(GPIOB_ODR_Addr,n)  //���
#define PBin(n)    BIT_ADDR(GPIOB_IDR_Addr,n)  //����

#define PCout(n)   BIT_ADDR(GPIOC_ODR_Addr,n)  //���
#define PCin(n)    BIT_ADDR(GPIOC_IDR_Addr,n)  //����

#define PDout(n)   BIT_ADDR(GPIOD_ODR_Addr,n)  //���
#define PDin(n)    BIT_ADDR(GPIOD_IDR_Addr,n)  //����

#define PEout(n)   BIT_ADDR(GPIOE_ODR_Addr,n)  //���
#define PEin(n)    BIT_ADDR(GPIOE_IDR_Addr,n)  //����

#define PFout(n)   BIT_ADDR(GPIOF_ODR_Addr,n)  //���
#define PFin(n)    BIT_ADDR(GPIOF_IDR_Addr,n)  //����

#define PGout(n)   BIT_ADDR(GPIOG_ODR_Addr,n)  //���
#define PGin(n)    BIT_ADDR(GPIOG_IDR_Addr,n)  //����

// added by anve 2018.1.28
#define PHout(n)   BIT_ADDR(GPIOH_ODR_Addr,n)  //���
#define PHin(n)    BIT_ADDR(GPIOH_IDR_Addr,n)  //����

#define PIout(n)   BIT_ADDR(GPIOI_ODR_Addr,n)  //���
#define PIin(n)    BIT_ADDR(GPIOI_IDR_Addr,n)  //����

#define PJout(n)   BIT_ADDR(GPIOJ_ODR_Addr,n)  //���
#define PJin(n)    BIT_ADDR(GPIOJ_IDR_Addr,n)  //����

#define PKout(n)   BIT_ADDR(GPIOK_ODR_Addr,n)  //���
#define PKin(n)    BIT_ADDR(GPIOK_IDR_Addr,n)  //����

//#define SysDelay1ms HAL_Delay


typedef struct {
	int left;
	int right;
	int top;
	int bottom;	
} CRect;

typedef void (*CallbackFunc) (void); 

typedef  void (*pFunction)(void);


#define DEBUG_UART_1   1


#endif /* DEFINE_H_ */
